package org.grow.memory.controller;

import org.grow.memory.domain.Bird;
import org.grow.memory.domain.Person;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Random;

@RestController
public class Basic {

    private Random random = new Random();

    private String randomString(String prefix){
        return prefix+"_"+(random.nextInt(8999)+1000);
    }

    @PutMapping("/person")
    public Person savePerson(@RequestBody Person person){
        person.setPersonCode(this.randomString("Person"));
        person.setLastTime(LocalDateTime.now());

        return person;
    }
    @PutMapping("/bird")
    public Bird saveBird(@RequestBody Bird bird){
        bird.setBirdCode(this.randomString("Bird"));
        bird.setCreateTime(LocalDateTime.now());

        return bird;
    }



}
